/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#ifndef OMEN_PLUGIN_H
#define OMEN_PLUGIN_H

#include "OmenConfig.h"
#include "OmenSharedLibrary.h"
#include "IOmenKernel.h"


#include <string>

namespace Omen {

  /// Representation of a plugin
  class Plugin
  {
    private:
        typedef int GetEngineVersionFunction();                         /// <summary>Signature for the version query function</summary>
        typedef void RegisterPluginFunction( Omen::IKernel* kernel);    /// <summary>Signature for the plugin's registration function</summary>
    
    public:
        OMEN_API Plugin(const std::wstring &filename);  /// <summary>Initializes and loads a plugin</summary>
                                                        /// <param name="filename">Filename of the plugin to load</summary>
        OMEN_API Plugin(const Plugin &other);
        
        OMEN_API ~Plugin();                             /// <summary>Unloads the plugin</summary>

        
        OMEN_API int getEngineVersion() const           /// <summary>Queries the plugin for its expected engine version</summary>
        {
            return getEngineVersionAddress();
        }

    
        OMEN_API void registerPlugin( Omen::IKernel* kernel);   /// <summary>Register the plugin to a kernel</summary>
                                                                /// <param name="kernel">Kernel the plugin should register to</param>

        Plugin &operator =(const Plugin &other);                /// <summary>Creates a copy of the plugin instance</summary>

    private:
        SharedLibrary::HandleType   sharedLibraryHandle;        /// <summary>Handle of the loaded shared library</summary>
        size_t*                     referenceCount;             /// <summary>Number of references that exist to the shared library</summary>
        GetEngineVersionFunction*   getEngineVersionAddress;    /// <summary>Function to query for the expected engine version</summary>
        RegisterPluginFunction*     registerPluginAddress;      /// <summary>Registers the plugin with the kernel</summary>

  };

  // ----------------------------------------------------------------------- //

} // namespace Omen

#endif // OMEN_PLUGIN_H
